package com.bbg.amyam.web.service.login;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;

import com.bbg.amyam.web.mvc.exception.NoSchoolFoundException;
import com.bbg.amyam.web.util.RequestPathParameter;
import com.bbg.amyam.web.util.RequestPathPaser;

public class LoginFailureService extends SimpleUrlAuthenticationFailureHandler {
	

	@Override
	public void onAuthenticationFailure(HttpServletRequest request,
			HttpServletResponse response, AuthenticationException exception)
			throws IOException, ServletException {
		
		String shortName="default";

			String para=request.getParameter("_uname");
			if(para!=null){
				shortName=para;
			}
		
			//String rUrl=request.getContextPath()+"/"+shortName+"/login?login_error=1";
		//response.sendRedirect(rUrl);
		super.setDefaultFailureUrl("/"+shortName+"/login?login_error=1");
		super.onAuthenticationFailure(request, response, exception);
		
	}

}
